﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;


using System.Collections;

namespace GPCSC.Webs
{
  public  class databyhtable
    {
        public databyhtable()
        { 
        
        }
  /// <summary>
  /// 
  /// </summary>
  /// <param name="htable"></param>
  /// <param name="type"></param>
  /// <param name="tablename"></param>
  /// <param name="prekid"></param>
  /// <param name="prevalue"></param>
        public void databyhtables(Hashtable htable, string type,string tablename,string prekid,string prevalue)
        {

           
            System.Collections.IDictionaryEnumerator enumerator = htable.GetEnumerator();
            StringBuilder strSql = new StringBuilder();
            if (type == "add")
            {
                strSql.Append("insert into " + tablename + "(");

                string sd = "";
                while (enumerator.MoveNext())
                {

                    if (enumerator.Key.ToString() == "errMsg")
                    {
                        continue;
                    }
                    if (enumerator.Key.ToString() == "uiStatic")
                    {
                        continue;
                    }
                    sd += enumerator.Key.ToString() + ",";
                }
                sd = sd.Substring(0, sd.Length - 1);
                strSql.Append(sd);
                strSql.Append(")");
                strSql.Append(" values (");
                string ss = "";
                System.Collections.IDictionaryEnumerator enumerators = htable.GetEnumerator();
                while (enumerators.MoveNext())
                {
                    if (enumerators.Key.ToString() == "errMsg")
                    {
                        continue;
                    }
                    if (enumerators.Key.ToString() == "uiStatic")
                    {
                        continue;
                    }
                    ss += "'" + enumerators.Value.ToString() + "',";

                }
                ss = ss.Substring(0, ss.Length - 1);
                strSql.Append(ss);
                strSql.Append(")");
            }
            else if (type == "update")
            {
                strSql.Append("update " + tablename + " set ");
                string sd = "";
                while (enumerator.MoveNext())
                {

                    if (enumerator.Key.ToString() == "errMsg")
                    {
                        continue;
                    }
                    if (enumerator.Key.ToString() == "uiStatic")
                    {
                        continue;
                    }
                    sd += enumerator.Key.ToString() + "='"+enumerator.Value.ToString()+"',";
                }
                sd = sd.Substring(0, sd.Length - 1);
                strSql.Append(sd);

              

                strSql.Append("where " + prekid + "='" + prevalue + "'");
               


            }

            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
    }
}
